#include <cstdio>
#include <vector>
#include <queue>

using namespace std;

vector<int> edge[501];
queue<int> node_queue;

int main(int argc, char const *argv[]) {
    int in_degree[501];
    int n, m;
    while (scanf("%d%d", &n, &m) != EOF) {
        if (n == 0 && m == 0)
            break;
        for (int i = 0; i < n; ++i) {
            in_degree[i] = 0;
            edge[i].clear();
        }
        for (int i = 0; i < m; ++i) {
            int a, b;
            scanf("%d%d", &a, &b);
            in_degree[b]++;
            edge[a].push_back(b);
        }
        //clear
        while (!node_queue.empty())
            node_queue.pop();
        for (int i = 0; i < n; ++i) {
            if (in_degree[i] == 0)
                node_queue.push(i);
        }
        int node_count = 0;
        while (!node_queue.empty()) {
            int now_node = node_queue.front();
            node_queue.pop();
            node_count++;
            for (int i = 0; i < edge[now_node].size(); ++i) {
                in_degree[edge[now_node][i]]--;
                if (in_degree[edge[now_node][i]] == 0)
                    node_queue.push(edge[now_node][i]);
            }
        }
        if (node_count == n)
            puts("YES");
        else
            puts("NO");
    }
    return 0;
}